import React from "react";
import { Link } from "react-router-dom";

export default function goods(props) {
  let { getgoods, n ,onChangeN} = props;
    
  let title = ["时令水果", "新鲜蔬菜", "肉禽蛋品", "粮油调味"]

  return (
    <div>
      <div className="goods">
        {title.map((item, index) => {
          return (
            <span
              key={index}
              onClick={() => onChangeN(index)}
              className={n == index ? "active" : null}>
              {item}
            </span>
          );
        })}
        
      </div>
      {getgoods.length > 0 ? (
          <div>
            {getgoods[n].content.map((i, index) => {
              return (
                <div key={i.id} className="every">
                  <Link to={"/detail/" + i.id}>
                    <p>商品名称{i.goodsname}</p>
                    <p>商品价格{i.price}</p>
                    <p>市场价格{i.market_price}</p>{" "}
                  </Link>
                </div>
              );
            })}
          </div>
        ) : (
          <div>暂无数据 </div>
        )}
    </div>
  );
}
